<?

/*	CalendarDay OBJECT
*	Comment here
*	
*					*/


class CalendarDay extends MOD {

	function __construct( $vars ) {
		
		$this->_addvars( $vars );
		$this->_ref();
	}
	
	var $days =		array(
		"nl" =>		array( 0, "zondag", "maandag", "dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag" )
	);
	
	public function construct() {
		global $DB, $CAL, $Page, $Cal, $Children;
		
		$CAL = new CALENDAR( "%d.%m %y" );

		if(!($id = $_GET[ "calid" ]) && !( $id = $_GET[ "id" ] ) && !$id = $this->vars->id )
			
			 $Cal = array_pop( $CAL->filter_nodes( false, 365, "cal.single", null, null, 1 ));
		else $Cal = new CALNODE( $this->vars->type, (int) $id );
		
		$Children = $CAL->filter_nodes( $CAL->smartday( $Cal->get( "date" )), 1 ); //3963&fresh=lang:nl


		$Page->set_cache( "title", $Cal->date( "%w d.m Y" ));
	}

	
	public function output() {
	
		if( $this->action )
			$nodes = $this->{ "filter_" . $this->action }();
	
		$this->addclass( $this->action );
		
		$result = ( $nodes ) ?
			"<ul>" . implode("\n", $nodes ) . "</ul>\n" . $script : "empty.";
	
	
		return $this->parse( $result );
	}
	
	
	
	
	private function filter_overview() {
		global $DB, $Engine, $Children, $Cal;
		
		if( $Children ) {
			foreach( $Children as $node ) {
			
				$text = ( $id = $node->get( 'textid' ))? $Engine->text->get( $id, "long" ) : "";
			
				if( $node->get( "objid" ) ) {
					$content = "<span class='time'>{$node->get( 'timestr' )}</span><a class='name' href='{$node->obj->url()}'>{$node->obj->get( 'name' )}</a>{$this->objTag( $node->loc, 'loc', 1 )}{$this->objTag( $node->obj )}<span class='descr'>$text</span>";
					$lines[] = ( $with_nfo )? "<li class='obj'>$content</li>" : "<li class='none'>$content<span class='cont'>" . substr( strip_tags( $Engine->text->get( $node->obj->get( "textid" ), "long" )), 0, 178 ). " ...</span></li>";
				} else {
					$with_nfo = true;
					$lines[] = "<li class='nfo'><h1>{$node->get( 'name' )}</h1>$text</li>";
				}
				
					
			}
		} else {
		
			$lines[] = '<li class="none">' . translate( 'empty' ) . '</li>';
		}
		
		return $lines;
	}	
	
	
	private function filter_list() {
		global $DB, $Engine, $Cal, $Children;
		
		if( $Children ) {
		
			$this->set_title( $Children[ 0 ]->get( "datestr" ));
		
			$lines[] = "<li class='descr'>". $this->days[ LANG ][ $Children[ 0 ]->get( "day" )] ."</li>";
		
			foreach( $Children as $node ) if( $node->obj ) {
				
				$class = ( $node->obj->type == $DB->type( $this->vars->secondary ))? "second" : "";
				$class.= ( $node->id == $Cal->id )? "active" : "";
				
				$lines[] = "<li class='$class'><a href='{$node->obj->uri()}'>{$node->obj->get( 'name' )}</a></li>";
			}
		} else {
		
			$this->set_title( date( 'd.m y', time()));
			$lines[] = "<li class='descr'>". $this->days[ LANG ][ date( 'w', time()) + 1 ] ."</li>";
			$lines[] = "<li class='active'>empty</li>";
		}
		
		return $lines;
	}



	private function filter_media() {
		global $DB, $Children;
		
		$IMG = new MEDIA( $this->vars );
		
		if( $Children )
			foreach ( $Children as $node )
				if( $node->obj && $node->obj->hasMedia())
				
					$nodes[] = "<li><a href='{$node->obj->uri()}'>" . $IMG->_img( array( "imgid"=> $node->obj->media->get( $this->vars->type )->ID, "alt"=> $node->obj->get( "name" ))) . "</a></li>";
				
		
		return $nodes;
		
	}
	
	private function objTag( $Obj, $type = "bio", $name = false ) {
		
		$name = ( $name )? $Obj->get( 'name' ) : $type;

		return "<a href='{$Obj->uri()}' class='$type'>$name</a>";
	}	


} 

?>


